package mis.ds.ps.model.factories;

import mis.ds.ps.model.dao.AulasDao;
import mis.ds.ps.model.dao.CursosDao;
import mis.ds.ps.model.dao.DisciplinasDao;
import mis.ds.ps.model.dao.DocentesDao;
import mis.ds.ps.model.dao.HorariosDao;
import mis.ds.ps.model.dao.ModulosDao;
import mis.ds.ps.model.dao.SalasDao;
import mis.ds.ps.model.dao.SiglasTiposDeAulasDao;
import mis.ds.ps.model.dao.TabelasDao;
import mis.ds.ps.model.dao.TabelasDisciplinasDao;
import mis.ds.ps.model.dao.TabelasDisciplinasTurmasDao;
import mis.ds.ps.model.dao.TemposEvitarDao;
import mis.ds.ps.model.dao.TemposOcupadosSalasDao;
import mis.ds.ps.model.dao.TiposDeAulasDao;
import mis.ds.ps.model.dao.TurmasDao;
import mis.ds.ps.model.dao.TurmasModulosDao;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

/**
 * DAO factory implementation.
 * 
 * @author autogenerated
 */
@Component
public class HibernateTimetableDaoFactory implements ApplicationContextAware,
		BeanNameAware {
	/** Placeholder for an instance. */
	private static HibernateTimetableDaoFactory instance;
	/** Internal state. */
	private static ApplicationContext context = null;
	/** Bean Name. */
	private static String beanName;

	/**
	 * Return an instance of this class.
	 * 
	 * @return an instance of this class
	 */
	public static synchronized HibernateTimetableDaoFactory getInstance() {
		if (instance == null) {
			instance = (HibernateTimetableDaoFactory) context.getBean(beanName);
		}
		return instance;
	}

	/**
	 * Sets a Spring Application Context object.
	 * 
	 * @param ctxt
	 *            ApplicationContext to set
	 * @throws BeansException
	 *             on spring error
	 */
	@Autowired
	public void setApplicationContext(ApplicationContext ctxt)
			throws BeansException {
		context = ctxt;
	}

	/**
	 * 
	 * {@inheritDoc}
	 * 
	 * @see org.springframework.beans.factory.BeanNameAware#setBeanName(java.lang.String)
	 */
	public void setBeanName(String name) {
		beanName = name;
	}

	/**
	 * Return the requested bean from the context, throwing a RuntimeException
	 * on error.
	 * 
	 * @param beanName
	 *            to return
	 * @return the bean requested.
	 */
	public static Object getBean(String beanName) {
		Object result = context.getBean(beanName);
		if (result == null) {
			throw new IllegalStateException(
					String.format(
							"Could not find bean '%s'. Did you set the right component scanning?",
							beanName));
		}

		return result;
	}

	/**
	 * Returns a AulasDao instance.
	 * 
	 * @return a AulasDao instance
	 */
	public static AulasDao getAulasDao() {
		return (AulasDao) getBean("aulasDaoImpl");
	}

	/**
	 * Returns a CursosDao instance.
	 * 
	 * @return a CursosDao instance
	 */
	public static CursosDao getCursosDao() {
		return (CursosDao) getBean("cursosDaoImpl");
	}

	/**
	 * Returns a DisciplinasDao instance.
	 * 
	 * @return a DisciplinasDao instance
	 */
	public static DisciplinasDao getDisciplinasDao() {
		return (DisciplinasDao) getBean("disciplinasDaoImpl");
	}

	/**
	 * Returns a DocentesDao instance.
	 * 
	 * @return a DocentesDao instance
	 */
	public static DocentesDao getDocentesDao() {
		return (DocentesDao) getBean("docentesDaoImpl");
	}

	/**
	 * Returns a HorariosDao instance.
	 * 
	 * @return a HorariosDao instance
	 */
	public static HorariosDao getHorariosDao() {
		return (HorariosDao) getBean("horariosDaoImpl");
	}

	/**
	 * Returns a ModulosDao instance.
	 * 
	 * @return a ModulosDao instance
	 */
	public static ModulosDao getModulosDao() {
		return (ModulosDao) getBean("modulosDaoImpl");
	}

	/**
	 * Returns a SalasDao instance.
	 * 
	 * @return a SalasDao instance
	 */
	public static SalasDao getSalasDao() {
		return (SalasDao) getBean("salasDaoImpl");
	}

	/**
	 * Returns a SiglasTiposDeAulasDao instance.
	 * 
	 * @return a SiglasTiposDeAulasDao instance
	 */
	public static SiglasTiposDeAulasDao getSiglasTiposDeAulasDao() {
		return (SiglasTiposDeAulasDao) getBean("siglasTiposDeAulasDaoImpl");
	}

	/**
	 * Returns a TabelasDao instance.
	 * 
	 * @return a TabelasDao instance
	 */
	public static TabelasDao getTabelasDao() {
		return (TabelasDao) getBean("tabelasDaoImpl");
	}

	/**
	 * Returns a TabelasDisciplinasDao instance.
	 * 
	 * @return a TabelasDisciplinasDao instance
	 */
	public static TabelasDisciplinasDao getTabelasDisciplinasDao() {
		return (TabelasDisciplinasDao) getBean("tabelasDisciplinasDaoImpl");
	}

	/**
	 * Returns a TabelasDisciplinasTurmasDao instance.
	 * 
	 * @return a TabelasDisciplinasTurmasDao instance
	 */
	public static TabelasDisciplinasTurmasDao getTabelasDisciplinasTurmasDao() {
		return (TabelasDisciplinasTurmasDao) getBean("tabelasDisciplinasTurmasDaoImpl");
	}

	/**
	 * Returns a TemposEvitarDao instance.
	 * 
	 * @return a TemposEvitarDao instance
	 */
	public static TemposEvitarDao getTemposEvitarDao() {
		return (TemposEvitarDao) getBean("temposEvitarDaoImpl");
	}

	/**
	 * Returns a TemposOcupadosSalasDao instance.
	 * 
	 * @return a TemposOcupadosSalasDao instance
	 */
	public static TemposOcupadosSalasDao getTemposOcupadosSalasDao() {
		return (TemposOcupadosSalasDao) getBean("temposOcupadosSalasDaoImpl");
	}

	/**
	 * Returns a TiposDeAulasDao instance.
	 * 
	 * @return a TiposDeAulasDao instance
	 */
	public static TiposDeAulasDao getTiposDeAulasDao() {
		return (TiposDeAulasDao) getBean("tiposDeAulasDaoImpl");
	}

	/**
	 * Returns a TurmasDao instance.
	 * 
	 * @return a TurmasDao instance
	 */
	public static TurmasDao getTurmasDao() {
		return (TurmasDao) getBean("turmasDaoImpl");
	}

	/**
	 * Returns a TurmasModulosDao instance.
	 * 
	 * @return a TurmasModulosDao instance
	 */
	public static TurmasModulosDao getTurmasModulosDao() {
		return (TurmasModulosDao) getBean("turmasModulosDaoImpl");
	}

}
